package operation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

public class Back implements Canoperation {
    public void work(Booklist booklist) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要归还的书籍");
        String name = sc.nextLine();
        int sum = booklist.getBooksum();
        for (int i = 0; i < sum; i++) {
            Book book = booklist.getbook(i);
            if (name.equals(book.getName())) {
                if (book.getisIsborrow()) {
                    System.out.println("归还成功");
                    book.setIsborrow(false);
                    return;
                } else {
                    System.out.println("归还的书不属于本图书馆");
                    return;
                }
            }
        }
        System.out.println("此书图书馆没有记录，可联系管理员添加");
    }
}
